# Maintainer: Evangelos Foutras <evangelos@foutrelis.com>
# Contributor: Jan "heftig" Steffens <jan.steffens@gmail.com>

pkgname=lldb
pkgver=12.0.1
pkgrel=1
pkgdesc="Next generation, high-performance debugger"
arch=('x86_64')
url="https://lldb.llvm.org/"
license=('custom:Apache 2.0 with LLVM Exception')
depends=('llvm-libs' 'clang' 'python' 'python-six')
makedepends=('llvm' 'cmake' 'ninja' 'swig' 'python-sphinx')
_source_base=https://github.com/llvm/llvm-project/releases/download/llvmorg-$pkgver
source=($_source_base/$pkgname-$pkgver.src.tar.xz{,.sig}
        support-DWARF-5-DW_FORM_line_strp-used-by-GCC.patch
        lldb-no-sphinx-automodapi.patch)
sha256sums=('e8c4118cd01d4e242090741a457d83c21754ad77299791ef564e41366a90773c'
            'SKIP'
            'd3f689fcfc40fb5219056c38f25cdbea95acf1f439b792ef043505ef22091909'
            '08e31dbaeffc77caf6c77771814e4c5aefa4cfa2cf33ff5fe1ad7ca8b35e5dd4')
validpgpkeys+=('B6C8F98282B944E3B0D5C2530FC3042E345AD05D') # Hans Wennborg <hans@chromium.org>
validpgpkeys+=('474E22316ABF4785A88C6E8EA2C794A986419D8A') # Tom Stellard <tstellar@redhat.com>

prepare() {
  cd "$srcdir/$pkgname-$pkgver.src"
  mkdir build

  # https://reviews.llvm.org/D97721
  patch -Np2 -i ../support-DWARF-5-DW_FORM_line_strp-used-by-GCC.patch

  # sphinx-automodapi is not needed to generate the man page
  patch -Np2 -i ../lldb-no-sphinx-automodapi.patch
}

build() {
  cd "$srcdir/$pkgname-$pkgver.src/build"

  cmake .. -G Ninja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DLLVM_LINK_LLVM_DYLIB=ON \
    -DCLANG_LINK_CLANG_DYLIB=ON \
    -DLLVM_ENABLE_SPHINX=ON \
    -DLLDB_USE_SYSTEM_SIX=1
  ninja all docs-lldb-man
}

package() {
  cd "$srcdir/$pkgname-$pkgver.src/build"

  DESTDIR="$pkgdir" ninja install
  install -Dm644 ../LICENSE.TXT "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  install -Dm644 docs/man/lldb.1 "$pkgdir/usr/share/man/man1/lldb.1"

  # Compile Python scripts
  python3 -m compileall "$pkgdir"
  python3 -O -m compileall "$pkgdir"
  python3 -OO -m compileall "$pkgdir"
}

# vim:set ts=2 sw=2 et:
